﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ShakeIt_.ServiceReference2;
using System.ComponentModel;

namespace ShakeIt_
{
    public partial class myMessagePage : PhoneApplicationPage
    {
        private List<_Chat> _chats;

        public List<_Chat> Chats
        {
            set
            {
                if (value != _chats)
                {
                    _chats = value;
                    NotifyPropertyChanged("Comments");
                }
            }
            get
            {
                return _chats;
            }
        }

        public myMessagePage()
        {
            InitializeComponent();
            /* 1. 保存纸条的List : List<_Chat> messageList
             *     _Chat的属性：private string chatContent { get; set; }
             *                       private DateTime sendTime { get; set; }
             *                       private _User sendMember { get; set; }
             *                       private _User receiveMember { get; set; }
             * 2.点击 <回复纸条> 按钮
             *     2.1 Data.userFocusedId = <目标>.id
             *     2.2 Data.userFocusedName = <目标>.username
             *     2.3 跳转到 sendMessagePage.xaml
             */
            Data.proxy.FindChatByReceiveIdCompleted +=new EventHandler<FindChatByReceiveIdCompletedEventArgs>(FindChatByReceiveIdCompleted);
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            Chats = null;
            chatBox.ItemsSource = null;

            Chats = Data.messageList;
            chatBox.ItemsSource = Chats;
        }

        private void FindChatByReceiveIdCompleted(object sender, FindChatByReceiveIdCompletedEventArgs e)
        {
            Chats = null;
            chatBox.ItemsSource = null;

            Chats = e.Result.ToList();
            chatBox.ItemsSource = Chats;
        }
    }

    public partial class myMessagePage : INotifyPropertyChanged
    {
        #region Property Changed

        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        #endregion
    }
}